6.3 How to prevent duplicate form submission

  1. Motivations
  2. How to prevent duplicate form submission
    • Read the 3rd paragraphs in Post/Redirect/Get.
    • Read Redirect After Post.
    • from http://blog.andreloker.de/post/2008/06/Post-Redirect-Get.aspx
    • How to redirect?
      // After the POST at the server,
      header("Location: " . $_SERVER['REQUEST_URI']);  // Or other content as the result of the POST request
      // When 'refresh' is clicked, the browser will send GET with the URI to the server, and
      //   the server script of the URI sends HTML content or data
      
    • With Ajax? No resubmission.
  3. SignIn in TRUQA - how to block the resubmission of username and password
    'SignIn':
        ...
        // include 'view_mainpage.php';  // Instead of this
        header('Location: view_mainpage.php');  // The browser will see 'view_mainpage.php' as a new page. The problem is that the session will be broken.
    

  4. Learning outcomes
    • Use of PRG pattern